package cn.trigram.validation.annotation.validator;

import cn.trigram.validation.annotation.DateFormatCheck;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;

/**
 * 字符日期时间格式校验器
 *
 * @version 1.0.0
 * @date 2022/08/04 09:11:06
 * @since 1.0.0
 */
public class DateFormatForStringValidator extends AbstractDateFormatValidator implements ConstraintValidator<DateFormatCheck, String> {

    @Override
    public void initialize(DateFormatCheck dateFormatCheck) {
        super.initialize(dateFormatCheck);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (!dateFormatCheck.required() || StringUtils.isBlank(value)) {
            return true;
        }
        return super.isValid(value, context);
    }
}